import React, {ReactNode} from 'react';
import {Redirect} from 'umi';
import {stringify} from 'querystring';
import {getUserToken} from "@/utils/utils";

function AuthLayout(props: { children?: ReactNode }) {
  const {children} = props;
  // const [isReady, setIsReady] = useState(false);

  // useEffect(() => {
  //   setIsReady(true);
  // }, []);

  const isLogin = getUserToken();

  // if (!isReady) {
  //   return <PageLoading/>;
  // }

  if(isLogin){
    return children;
  }
  if (window.location.pathname === '/login'){
    return (<></>);
  }
  const queryString = stringify({redirect: window.location.href,});
  return (<Redirect to={`/login?${queryString}`}/>);
}

export default AuthLayout;
